<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\MallOrderList;

/**
 * MallOrderListSearch represents the model behind the search form of `backend\models\MallOrderList`.
 */
class MallOrderListSearch extends MallOrderList
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'mid', 'pid', 'count', 'create_time', 'uid', 'sku_id'], 'integer'],
            [['out_trade_no', 'product_no', 'value'], 'safe'],
            [['logistic', 'price', 'total_fee', 'amount', 'level_one', 'level_two'], 'number'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = MallOrderList::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'mid' => $this->mid,
            'pid' => $this->pid,
            'logistic' => $this->logistic,
            'price' => $this->price,
            'count' => $this->count,
            'create_time' => $this->create_time,
            'total_fee' => $this->total_fee,
            'uid' => $this->uid,
            'sku_id' => $this->sku_id,
            'amount' => $this->amount,
            'level_one' => $this->level_one,
            'level_two' => $this->level_two,
        ]);

        $query->andFilterWhere(['like', 'out_trade_no', $this->out_trade_no])
            ->andFilterWhere(['like', 'product_no', $this->product_no])
            ->andFilterWhere(['like', 'value', $this->value]);

        return $dataProvider;
    }
}
